package com.yk.web.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yk.common.annotation.Log;
import com.yk.common.enums.BusinessType;
import com.yk.course.domain.CourseType;
import com.yk.course.service.ICourseTypeService;
import com.yk.common.core.controller.BaseController;
import com.yk.common.core.domain.AjaxResult;
import com.yk.common.utils.poi.ExcelUtil;
import com.yk.common.core.page.TableDataInfo;
import org.springframework.stereotype.Controller;

/**
 * 课程分类Controller
 * 
 * @author xufei
 * @date 2025-04-28
 */
@Controller
@RequestMapping("/course/courseType")
public class CourseTypeController extends BaseController
{
    private String prefix = "course/courseType";

    @Autowired
    private ICourseTypeService courseTypeService;

    @RequiresPermissions("course:courseType:view")
    @GetMapping()
    public String courseType()
    {
        return prefix + "/courseType";
    }

    /**
     * 查询课程分类列表
     */
    @RequiresPermissions("course:courseType:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CourseType courseType)
    {
        startPage();
        List<CourseType> list = courseTypeService.selectCourseTypeList(courseType);
        return getDataTable(list);
    }

    /**
     * 导出课程分类列表
     */
    @RequiresPermissions("course:courseType:export")
    @Log(title = "课程分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CourseType courseType)
    {
        List<CourseType> list = courseTypeService.selectCourseTypeList(courseType);
        ExcelUtil<CourseType> util = new ExcelUtil<CourseType>(CourseType.class);
        return util.exportExcel(list, "课程分类数据");
    }

    /**
     * 新增课程分类
     */
    @RequiresPermissions("course:courseType:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存课程分类
     */
    @RequiresPermissions("course:courseType:add")
    @Log(title = "课程分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CourseType courseType)
    {
        return toAjax(courseTypeService.insertCourseType(courseType));
    }

    /**
     * 修改课程分类
     */
    @RequiresPermissions("course:courseType:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CourseType courseType = courseTypeService.selectCourseTypeById(id);
        mmap.put("courseType", courseType);
        return prefix + "/edit";
    }

    /**
     * 修改保存课程分类
     */
    @RequiresPermissions("course:courseType:edit")
    @Log(title = "课程分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CourseType courseType)
    {
        return toAjax(courseTypeService.updateCourseType(courseType));
    }

    /**
     * 删除课程分类
     */
    @RequiresPermissions("course:courseType:remove")
    @Log(title = "课程分类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(courseTypeService.deleteCourseTypeByIds(ids));
    }
}
